<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="../reset.css" />
    <style>
      .container {
        max-width: 1500px;
        height: 100px;
        margin-top: 5rem;
        margin-inline: auto; /* 水平居中 */
        /* 关键代码： */
        position: relative;
        overflow: hidden;
        mask-image: linear-gradient(
          to right,
          transparent,
          black 20%,
          black 80%,
          transparent
        );
      }

      .container:hover .item {
        animation-play-state: paused;
      }

      @keyframes scrollLeft {
        to {
          left: -200px;
        }
      }

      .item {
        width: 200px;
        height: 100px;
        background-color: red;
        border-radius: 6px;
        font-size: 20px;
        text-align: center;
        line-height: 100px;
        /* 关键代码：绝对定位 */
        position: absolute;
        left: max(calc(200px * 8), 100%);
        animation: scrollLeft 30s linear infinite;
        cursor: pointer;
        user-select: none;
      }

      /* 乘-1让delay的值为负数，是为了让wrapper中一开始就有内容 */
      .item1 {
        animation-delay: calc(30s / 8 * (8 - 1) * -1);
      }
      .item2 {
        animation-delay: calc(30s / 8 * (8 - 2) * -1);
      }
      .item3 {
        animation-delay: calc(30s / 8 * (8 - 3) * -1);
      }
      .item4 {
        animation-delay: calc(30s / 8 * (8 - 4) * -1);
      }
      .item5 {
        animation-delay: calc(30s / 8 * (8 - 5) * -1);
      }
      .item6 {
        animation-delay: calc(30s / 8 * (8 - 6) * -1);
      }
      .item7 {
        animation-delay: calc(30s / 8 * (8 - 7) * -1);
      }
      .item8 {
        animation-delay: calc(30s / 8 * (8 - 8) * -1);
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="item item1">1</div>
      <div class="item item2">2</div>
      <div class="item item3">3</div>
      <div class="item item4">4</div>
      <div class="item item5">5</div>
      <div class="item item6">6</div>
      <div class="item item7">7</div>
      <div class="item item8">8</div>
    </div>
  </body>
</html>
